﻿//Tên form : Phân quyền cho nhóm người dùng
//Mô tả: - Liệt kê danh sách nhóm người dùng và chức năng hiện tại của hệ thống phục vụ phân quyền truy cập
//Mô tả chi tiết các chức năng :
//		-Bước 1: Chọn nhóm người dùng cần phân quyền.
//		-Bước 2: Chọn các chức năng cho phép nhóm người dùng đó truy cập với các cấp độ: Xem, thêm, sửa, xóa, hiển thị.
//		-Bước 3: Lưu thông tin phân quyền vào cơ sở dữ liệu
//Các yêu cầu ràng buộc : Để tiện dụng cho người dùng, cây chức năng nên có chức năng check all cho các chức năng con của một sub chức năng.
//kiểm tra ràng buộc trước khi lưu vào cơ sở dữ liệu.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
using Infragistics.Win.UltraWinTabbedMdi;
using QLNHK.QUANTRIHETHONG;
using QLNHK.BLL;
using System.Data;
using Infragistics.Win;
using Infragistics.Win.UltraWinTree;
using Infragistics.Win.UltraWinEditors;
using System.Web;
using System.Web.Caching;

namespace QLNHK.QUANTRIHETHONG
{
    /// <summary>
    /// Summary description for FrmPhanQuyenNhomNguoiDung.
    /// </summary>
    public class FrmPhanQuyenNhomNguoiDung : FrmBase
    {
        private bool IsChange;
        private string caption;

        private Cls_PHANQUYEN_NHOM ObjPhanQuyen = new Cls_PHANQUYEN_NHOM();
        private Cls_DS_CHUCNANG ObjChucNang = new Cls_DS_CHUCNANG();
        private DataSet ds;
        private Infragistics.Win.UltraWinDataSource.UltraDataSource ultraDataSource1;
        private Infragistics.Win.UltraWinGrid.UltraCombo cboNhomNguoiDung;
        private Infragistics.Win.Misc.UltraLabel ultraLabel1;
        private Infragistics.Win.Misc.UltraGroupBox ultraGroupBox1;
        private Infragistics.Win.UltraWinTree.UltraTree trvDanhSachChucNang;
        private Infragistics.Win.Misc.UltraButton btnDong;
        private System.Windows.Forms.ImageList imgTree;
        private System.Data.DataSet dsPhanQuyen;
        private System.Data.DataTable dtPhanQuyen;
        private System.Data.DataColumn dataColumn1;
        private System.Data.DataColumn dataColumn2;
        private System.Data.DataColumn dataColumn3;
        private System.Data.DataColumn dataColumn4;
        private System.Data.DataColumn dataColumn5;
        private SecurityControl.SecurityControl scPhanQuyen;
        private Infragistics.Win.Misc.UltraButton btnLuu;
        private Infragistics.Win.Misc.UltraButton btnMoRong;
        private Infragistics.Win.Misc.UltraLabel ultraLabel3;
        private Infragistics.Win.Misc.UltraGroupBox ultraGroupBox2;
        private System.ComponentModel.IContainer components;

        public FrmPhanQuyenNhomNguoiDung()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmPhanQuyenNhomNguoiDung));
            Infragistics.Win.UltraWinDataSource.UltraDataColumn ultraDataColumn1 = new Infragistics.Win.UltraWinDataSource.UltraDataColumn("Tên chức năng");
            Infragistics.Win.UltraWinDataSource.UltraDataColumn ultraDataColumn2 = new Infragistics.Win.UltraWinDataSource.UltraDataColumn("Tick");
            Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
            Infragistics.Win.UltraWinTree.Override _override1 = new Infragistics.Win.UltraWinTree.Override();
            Infragistics.Win.UltraWinTree.Override _override2 = new Infragistics.Win.UltraWinTree.Override();
            Infragistics.Win.UltraWinTree.Override _override3 = new Infragistics.Win.UltraWinTree.Override();
            Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance9 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance10 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance11 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance12 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance13 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance14 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance15 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance16 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance17 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance18 = new Infragistics.Win.Appearance();
            this.ultraDataSource1 = new Infragistics.Win.UltraWinDataSource.UltraDataSource(this.components);
            this.imgTree = new System.Windows.Forms.ImageList(this.components);
            this.scPhanQuyen = new SecurityControl.SecurityControl();
            this.btnMoRong = new Infragistics.Win.Misc.UltraButton();
            this.btnLuu = new Infragistics.Win.Misc.UltraButton();
            this.btnDong = new Infragistics.Win.Misc.UltraButton();
            this.dsPhanQuyen = new System.Data.DataSet();
            this.dtPhanQuyen = new System.Data.DataTable();
            this.dataColumn1 = new System.Data.DataColumn();
            this.dataColumn2 = new System.Data.DataColumn();
            this.dataColumn3 = new System.Data.DataColumn();
            this.dataColumn4 = new System.Data.DataColumn();
            this.dataColumn5 = new System.Data.DataColumn();
            this.ultraGroupBox1 = new Infragistics.Win.Misc.UltraGroupBox();
            this.trvDanhSachChucNang = new Infragistics.Win.UltraWinTree.UltraTree();
            this.cboNhomNguoiDung = new Infragistics.Win.UltraWinGrid.UltraCombo();
            this.ultraLabel3 = new Infragistics.Win.Misc.UltraLabel();
            this.ultraLabel1 = new Infragistics.Win.Misc.UltraLabel();
            this.ultraGroupBox2 = new Infragistics.Win.Misc.UltraGroupBox();
            ((System.ComponentModel.ISupportInitialize)(this.ultraDataSource1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dsPhanQuyen)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dtPhanQuyen)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.ultraGroupBox1)).BeginInit();
            this.ultraGroupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.trvDanhSachChucNang)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.cboNhomNguoiDung)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.ultraGroupBox2)).BeginInit();
            this.ultraGroupBox2.SuspendLayout();
            this.SuspendLayout();
            // 
            // imgList
            // 
            this.imgList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgList.ImageStream")));
            this.imgList.Images.SetKeyName(0, "");
            this.imgList.Images.SetKeyName(1, "");
            this.imgList.Images.SetKeyName(2, "");
            this.imgList.Images.SetKeyName(3, "");
            this.imgList.Images.SetKeyName(4, "");
            this.imgList.Images.SetKeyName(5, "");
            this.imgList.Images.SetKeyName(6, "");
            this.imgList.Images.SetKeyName(7, "");
            this.imgList.Images.SetKeyName(8, "");
            this.imgList.Images.SetKeyName(9, "");
            this.imgList.Images.SetKeyName(10, "");
            this.imgList.Images.SetKeyName(11, "");
            this.imgList.Images.SetKeyName(12, "");
            this.imgList.Images.SetKeyName(13, "");
            this.imgList.Images.SetKeyName(14, "");
            this.imgList.Images.SetKeyName(15, "");
            this.imgList.Images.SetKeyName(16, "");
            this.imgList.Images.SetKeyName(17, "");
            this.imgList.Images.SetKeyName(18, "");
            this.imgList.Images.SetKeyName(19, "");
            this.imgList.Images.SetKeyName(20, "");
            this.imgList.Images.SetKeyName(21, "");
            this.imgList.Images.SetKeyName(22, "");
            this.imgList.Images.SetKeyName(23, "");
            this.imgList.Images.SetKeyName(24, "enable_server.ico");
            this.imgList.Images.SetKeyName(25, "User.ico");
            this.imgList.Images.SetKeyName(26, "doc-file.ico");
            this.imgList.Images.SetKeyName(27, "xls-file.ico");
            this.imgList.Images.SetKeyName(28, "lock.ico");
            // 
            // ultraDataSource1
            // 
            ultraDataColumn2.DataType = typeof(bool);
            this.ultraDataSource1.Band.Columns.AddRange(new object[] {
            ultraDataColumn1,
            ultraDataColumn2});
            this.ultraDataSource1.Band.Key = "band";
            this.ultraDataSource1.Rows.AddRange(new object[] {
            new Infragistics.Win.UltraWinDataSource.UltraDataRow(new object[] {
                        ((object)("Tên chức năng")),
                        ((object)("Quản trị")),
                        ((object)("Tick")),
                        ((object)(false))}),
            new Infragistics.Win.UltraWinDataSource.UltraDataRow(new object[] {
                        ((object)("Tên chức năng")),
                        ((object)("Người dùng"))})});
            // 
            // imgTree
            // 
            this.imgTree.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgTree.ImageStream")));
            this.imgTree.TransparentColor = System.Drawing.Color.Transparent;
            this.imgTree.Images.SetKeyName(0, "LoadPageSetup_16x16.png");
            this.imgTree.Images.SetKeyName(1, "Folder_Closed.png");
            this.imgTree.Images.SetKeyName(2, "");
            this.imgTree.Images.SetKeyName(3, "");
            this.imgTree.Images.SetKeyName(4, "");
            this.imgTree.Images.SetKeyName(5, "Article_16x16.png");
            this.imgTree.Images.SetKeyName(6, "");
            this.imgTree.Images.SetKeyName(7, "");
            // 
            // scPhanQuyen
            // 
            this.scPhanQuyen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.scPhanQuyen.BackColor = System.Drawing.Color.Transparent;
            this.scPhanQuyen.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.scPhanQuyen.Location = new System.Drawing.Point(92, 432);
            this.scPhanQuyen.Name = "scPhanQuyen";
            this.scPhanQuyen.Size = new System.Drawing.Size(352, 32);
            this.scPhanQuyen.TabIndex = 11;
            this.scPhanQuyen.Value = "00000";
            this.scPhanQuyen.CheckBoxClicked += new SecurityControl.SecurityControl.CheckBoxClickedHandler(this.scPhanQuyen_CheckBoxClicked);
            // 
            // btnMoRong
            // 
            this.btnMoRong.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            appearance1.Image = ((object)(resources.GetObject("appearance1.Image")));
            this.btnMoRong.Appearance = appearance1;
            this.btnMoRong.BackColorInternal = System.Drawing.SystemColors.Control;
            this.btnMoRong.ImageList = this.imgTree;
            this.btnMoRong.Location = new System.Drawing.Point(297, 470);
            this.btnMoRong.Name = "btnMoRong";
            this.btnMoRong.Size = new System.Drawing.Size(196, 24);
            this.btnMoRong.TabIndex = 9;
            this.btnMoRong.Tag = "THUHEP";
            this.btnMoRong.Text = "Thu hẹp cây chức năng";
            this.btnMoRong.Click += new System.EventHandler(this.btnMoRong_Click);
            // 
            // btnLuu
            // 
            this.btnLuu.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            appearance2.Image = ((object)(resources.GetObject("appearance2.Image")));
            this.btnLuu.Appearance = appearance2;
            this.btnLuu.BackColorInternal = System.Drawing.SystemColors.Control;
            this.btnLuu.Location = new System.Drawing.Point(498, 470);
            this.btnLuu.Name = "btnLuu";
            this.btnLuu.Size = new System.Drawing.Size(88, 24);
            this.btnLuu.TabIndex = 8;
            this.btnLuu.Text = "&Lưu";
            this.btnLuu.Click += new System.EventHandler(this.btnLuu_Click);
            // 
            // btnDong
            // 
            this.btnDong.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            appearance3.Image = ((object)(resources.GetObject("appearance3.Image")));
            this.btnDong.Appearance = appearance3;
            this.btnDong.BackColorInternal = System.Drawing.SystemColors.Control;
            this.btnDong.Location = new System.Drawing.Point(591, 470);
            this.btnDong.Name = "btnDong";
            this.btnDong.Size = new System.Drawing.Size(82, 24);
            this.btnDong.TabIndex = 7;
            this.btnDong.Text = "Đó&ng";
            this.btnDong.Click += new System.EventHandler(this.btnDong_Click);
            // 
            // dsPhanQuyen
            // 
            this.dsPhanQuyen.DataSetName = "dsPhanQuyen";
            this.dsPhanQuyen.Locale = new System.Globalization.CultureInfo("en-US");
            this.dsPhanQuyen.Tables.AddRange(new System.Data.DataTable[] {
            this.dtPhanQuyen});
            // 
            // dtPhanQuyen
            // 
            this.dtPhanQuyen.Columns.AddRange(new System.Data.DataColumn[] {
            this.dataColumn1,
            this.dataColumn2,
            this.dataColumn3,
            this.dataColumn4,
            this.dataColumn5});
            this.dtPhanQuyen.TableName = "tb_PhanQuyen";
            // 
            // dataColumn1
            // 
            this.dataColumn1.ColumnName = "ID_Nhom_NguoiDung";
            this.dataColumn1.DataType = typeof(int);
            // 
            // dataColumn2
            // 
            this.dataColumn2.ColumnName = "ID_DS_ChucNang";
            this.dataColumn2.DataType = typeof(int);
            // 
            // dataColumn3
            // 
            this.dataColumn3.ColumnName = "MaTruyCap";
            // 
            // dataColumn4
            // 
            this.dataColumn4.ColumnName = "TrangThai";
            // 
            // dataColumn5
            // 
            this.dataColumn5.ColumnName = "ID_PhanQuyen_Nhom";
            this.dataColumn5.DataType = typeof(int);
            // 
            // ultraGroupBox1
            // 
            this.ultraGroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            appearance4.BackColor = System.Drawing.Color.Transparent;
            this.ultraGroupBox1.Appearance = appearance4;
            this.ultraGroupBox1.Controls.Add(this.trvDanhSachChucNang);
            this.ultraGroupBox1.Location = new System.Drawing.Point(92, 71);
            this.ultraGroupBox1.Name = "ultraGroupBox1";
            this.ultraGroupBox1.Size = new System.Drawing.Size(586, 355);
            this.ultraGroupBox1.TabIndex = 3;
            this.ultraGroupBox1.Text = "Danh sách chức năng";
            this.ultraGroupBox1.ViewStyle = Infragistics.Win.Misc.GroupBoxViewStyle.Office2007;
            // 
            // trvDanhSachChucNang
            // 
            this.trvDanhSachChucNang.Dock = System.Windows.Forms.DockStyle.Fill;
            this.trvDanhSachChucNang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.trvDanhSachChucNang.ImageList = this.imgTree;
            this.trvDanhSachChucNang.Location = new System.Drawing.Point(3, 17);
            this.trvDanhSachChucNang.Name = "trvDanhSachChucNang";
            this.trvDanhSachChucNang.NodeConnectorColor = System.Drawing.SystemColors.ActiveCaption;
            _override1.NodeStyle = Infragistics.Win.UltraWinTree.NodeStyle.CheckBox;
            _override2.NodeStyle = Infragistics.Win.UltraWinTree.NodeStyle.CheckBox;
            _override3.NodeStyle = Infragistics.Win.UltraWinTree.NodeStyle.CheckBox;
            this.trvDanhSachChucNang.NodeLevelOverrides.Add(_override1);
            this.trvDanhSachChucNang.NodeLevelOverrides.Add(_override2);
            this.trvDanhSachChucNang.NodeLevelOverrides.Add(_override3);
            this.trvDanhSachChucNang.Size = new System.Drawing.Size(580, 335);
            this.trvDanhSachChucNang.TabIndex = 0;
            this.trvDanhSachChucNang.ViewStyle = Infragistics.Win.UltraWinTree.ViewStyle.Standard;
            this.trvDanhSachChucNang.AfterCheck += new Infragistics.Win.UltraWinTree.AfterNodeChangedEventHandler(this.trvDanhSachChucNang_AfterCheck);
            this.trvDanhSachChucNang.BeforeCheck += new Infragistics.Win.UltraWinTree.BeforeCheckEventHandler(this.trvDanhSachChucNang_BeforeCheck);
            this.trvDanhSachChucNang.Click += new System.EventHandler(this.trvDanhSachChucNang_Click);
            this.trvDanhSachChucNang.MouseDown += new System.Windows.Forms.MouseEventHandler(this.trvDanhSachChucNang_MouseDown);
            // 
            // cboNhomNguoiDung
            // 
            this.cboNhomNguoiDung.CheckedListSettings.CheckStateMember = "";
            appearance5.BackColor = System.Drawing.SystemColors.Window;
            appearance5.BorderColor = System.Drawing.SystemColors.InactiveCaption;
            this.cboNhomNguoiDung.DisplayLayout.Appearance = appearance5;
            this.cboNhomNguoiDung.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
            this.cboNhomNguoiDung.DisplayLayout.CaptionVisible = Infragistics.Win.DefaultableBoolean.False;
            appearance6.BackColor = System.Drawing.SystemColors.ActiveBorder;
            appearance6.BackColor2 = System.Drawing.SystemColors.ControlDark;
            appearance6.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
            appearance6.BorderColor = System.Drawing.SystemColors.Window;
            this.cboNhomNguoiDung.DisplayLayout.GroupByBox.Appearance = appearance6;
            appearance7.ForeColor = System.Drawing.SystemColors.GrayText;
            this.cboNhomNguoiDung.DisplayLayout.GroupByBox.BandLabelAppearance = appearance7;
            this.cboNhomNguoiDung.DisplayLayout.GroupByBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
            appearance8.BackColor = System.Drawing.SystemColors.ControlLightLight;
            appearance8.BackColor2 = System.Drawing.SystemColors.Control;
            appearance8.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
            appearance8.ForeColor = System.Drawing.SystemColors.GrayText;
            this.cboNhomNguoiDung.DisplayLayout.GroupByBox.PromptAppearance = appearance8;
            this.cboNhomNguoiDung.DisplayLayout.MaxColScrollRegions = 1;
            this.cboNhomNguoiDung.DisplayLayout.MaxRowScrollRegions = 1;
            appearance9.BackColor = System.Drawing.SystemColors.Window;
            appearance9.ForeColor = System.Drawing.SystemColors.ControlText;
            this.cboNhomNguoiDung.DisplayLayout.Override.ActiveCellAppearance = appearance9;
            appearance10.BackColor = System.Drawing.SystemColors.Highlight;
            appearance10.ForeColor = System.Drawing.SystemColors.HighlightText;
            this.cboNhomNguoiDung.DisplayLayout.Override.ActiveRowAppearance = appearance10;
            this.cboNhomNguoiDung.DisplayLayout.Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.Dotted;
            this.cboNhomNguoiDung.DisplayLayout.Override.BorderStyleRow = Infragistics.Win.UIElementBorderStyle.Dotted;
            appearance11.BackColor = System.Drawing.SystemColors.Window;
            this.cboNhomNguoiDung.DisplayLayout.Override.CardAreaAppearance = appearance11;
            appearance12.BorderColor = System.Drawing.Color.Silver;
            appearance12.TextTrimming = Infragistics.Win.TextTrimming.EllipsisCharacter;
            this.cboNhomNguoiDung.DisplayLayout.Override.CellAppearance = appearance12;
            this.cboNhomNguoiDung.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.EditAndSelectText;
            this.cboNhomNguoiDung.DisplayLayout.Override.CellPadding = 0;
            appearance13.BackColor = System.Drawing.SystemColors.Control;
            appearance13.BackColor2 = System.Drawing.SystemColors.ControlDark;
            appearance13.BackGradientAlignment = Infragistics.Win.GradientAlignment.Element;
            appearance13.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
            appearance13.BorderColor = System.Drawing.SystemColors.Window;
            this.cboNhomNguoiDung.DisplayLayout.Override.GroupByRowAppearance = appearance13;
            appearance14.TextHAlignAsString = "Left";
            this.cboNhomNguoiDung.DisplayLayout.Override.HeaderAppearance = appearance14;
            this.cboNhomNguoiDung.DisplayLayout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortMulti;
            this.cboNhomNguoiDung.DisplayLayout.Override.HeaderStyle = Infragistics.Win.HeaderStyle.WindowsXPCommand;
            appearance15.BackColor = System.Drawing.SystemColors.Window;
            appearance15.BorderColor = System.Drawing.Color.Silver;
            this.cboNhomNguoiDung.DisplayLayout.Override.RowAppearance = appearance15;
            this.cboNhomNguoiDung.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False;
            appearance16.BackColor = System.Drawing.SystemColors.ControlLight;
            this.cboNhomNguoiDung.DisplayLayout.Override.TemplateAddRowAppearance = appearance16;
            this.cboNhomNguoiDung.DisplayLayout.ScrollBounds = Infragistics.Win.UltraWinGrid.ScrollBounds.ScrollToFill;
            this.cboNhomNguoiDung.DisplayLayout.ScrollStyle = Infragistics.Win.UltraWinGrid.ScrollStyle.Immediate;
            this.cboNhomNguoiDung.DisplayLayout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.OutlookGroupBy;
            this.cboNhomNguoiDung.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
            this.cboNhomNguoiDung.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cboNhomNguoiDung.ImageList = this.imgTree;
            this.cboNhomNguoiDung.Location = new System.Drawing.Point(92, 19);
            this.cboNhomNguoiDung.Name = "cboNhomNguoiDung";
            this.cboNhomNguoiDung.PreferredDropDownSize = new System.Drawing.Size(0, 0);
            this.cboNhomNguoiDung.Size = new System.Drawing.Size(287, 23);
            this.cboNhomNguoiDung.TabIndex = 0;
            this.cboNhomNguoiDung.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.cboNhomNguoiDung_InitializeLayout);
            this.cboNhomNguoiDung.ValueChanged += new System.EventHandler(this.cboNhomNguoiDung_ValueChanged);
            // 
            // ultraLabel3
            // 
            appearance17.BackColor = System.Drawing.Color.Transparent;
            this.ultraLabel3.Appearance = appearance17;
            this.ultraLabel3.AutoSize = true;
            this.ultraLabel3.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ultraLabel3.Location = new System.Drawing.Point(92, 50);
            this.ultraLabel3.Name = "ultraLabel3";
            this.ultraLabel3.Size = new System.Drawing.Size(476, 15);
            this.ultraLabel3.TabIndex = 1;
            this.ultraLabel3.Text = "Để phân quyền vui lòng chọn nhóm và thiết lập phân quyền ở danh sách chức năng bê" +
    "n dưới.";
            // 
            // ultraLabel1
            // 
            appearance18.BackColor = System.Drawing.Color.Transparent;
            this.ultraLabel1.Appearance = appearance18;
            this.ultraLabel1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ultraLabel1.Location = new System.Drawing.Point(20, 27);
            this.ultraLabel1.Name = "ultraLabel1";
            this.ultraLabel1.Size = new System.Drawing.Size(66, 15);
            this.ultraLabel1.TabIndex = 1;
            this.ultraLabel1.Text = "Chọn nhóm:";
            // 
            // ultraGroupBox2
            // 
            this.ultraGroupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.ultraGroupBox2.Controls.Add(this.ultraLabel3);
            this.ultraGroupBox2.Controls.Add(this.btnMoRong);
            this.ultraGroupBox2.Controls.Add(this.scPhanQuyen);
            this.ultraGroupBox2.Controls.Add(this.btnLuu);
            this.ultraGroupBox2.Controls.Add(this.ultraLabel1);
            this.ultraGroupBox2.Controls.Add(this.btnDong);
            this.ultraGroupBox2.Controls.Add(this.cboNhomNguoiDung);
            this.ultraGroupBox2.Controls.Add(this.ultraGroupBox1);
            this.ultraGroupBox2.Location = new System.Drawing.Point(-9, -5);
            this.ultraGroupBox2.Name = "ultraGroupBox2";
            this.ultraGroupBox2.Size = new System.Drawing.Size(692, 519);
            this.ultraGroupBox2.TabIndex = 12;
            this.ultraGroupBox2.ViewStyle = Infragistics.Win.Misc.GroupBoxViewStyle.Office2007;
            this.ultraGroupBox2.Click += new System.EventHandler(this.ultraGroupBox2_Click);
            // 
            // FrmPhanQuyenNhomNguoiDung
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.BackColor = System.Drawing.Color.White;
            this.ClientSize = new System.Drawing.Size(676, 501);
            this.Controls.Add(this.ultraGroupBox2);
            this.Name = "FrmPhanQuyenNhomNguoiDung";
            this.Text = "Phân quyền cho nhóm người dùng";
            this.Closing += new System.ComponentModel.CancelEventHandler(this.FrmPhanQuyenNhomNguoiDung_Closing);
            this.Load += new System.EventHandler(this.FrmPhanQuyenNhomNguoiDung_Load);
            ((System.ComponentModel.ISupportInitialize)(this.ultraDataSource1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dsPhanQuyen)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dtPhanQuyen)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.ultraGroupBox1)).EndInit();
            this.ultraGroupBox1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.trvDanhSachChucNang)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.cboNhomNguoiDung)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.ultraGroupBox2)).EndInit();
            this.ultraGroupBox2.ResumeLayout(false);
            this.ultraGroupBox2.PerformLayout();
            this.ResumeLayout(false);

        }
        #endregion

        private void setChanged(bool trangthai)
        {
            if (trangthai)
            {
                this.IsChange = true;
                this.Text = this.caption + "*";
                btnLuu.Enabled = true;
                btnDong.Enabled = true;
            }
            else
            {
                this.IsChange = false;
                this.Text = this.caption;
                btnLuu.Enabled = false;
            }
        }
        private void loadTreeDanhSachChucNang()
        {
            try
            {
                trvDanhSachChucNang.Nodes.Clear();
                DataTable dtbChucNang = ObjChucNang.ListByAll().Tables[0];
                //DataTable DtbPhongBan=(CacheUtil.Cache.Get("PhongBanCache") as DataView).Table; //table PhongBan			
                DataRow[] drChucNang;
                string ID_Goc = "frmMain";

                //Get root node, mặc định root node có [Parent]= frmMain
                //			drChucNang = dtbChucNang.Select("ID_Goc = 'frmMain'");//Alway has value
                //						
                //			//Thêm vào root Node
                //UltraTreeNode Node;
                UltraTreeNode NodeChild;
                //			Node=trvDanhSachChucNang.Nodes.Add();
                //			Node.Text = drChucNang[0]["Ten_HienThi"].ToString();
                //			ID_Goc = drChucNang[0]["ID_Goc"].ToString();
                //			Node.Key = drChucNang[0]["Ten"].ToString();;
                //			//Node.LeftImages.Add(0);
                //			Node.Expanded = true;

                drChucNang = dtbChucNang.Select("ID_Goc='" + ID_Goc + "'");//Alway has value
                foreach (DataRow dr in drChucNang)
                {
                    if (!trvDanhSachChucNang.Nodes.Exists("ROOT~" + dr["Ten"].ToString()))
                    {
                        NodeChild = trvDanhSachChucNang.Nodes.Add();
                        NodeChild.Text = dr["Ten_HienThi"].ToString();

                        NodeChild.Key = "ROOT~" + dr["Ten"].ToString();
                        NodeChild.Tag = dr["ID_DS_ChucNang"].ToString();
                        NodeChild.LeftImages.Add(0);
                        NodeChild.Override.ShowExpansionIndicator = ShowExpansionIndicator.CheckOnExpand;
                        NodeChild.Override.NodeDoubleClickAction = NodeDoubleClickAction.ToggleExpansionWhenExpansionIndicatorVisible;
                        loadTreeRecursive(NodeChild, dr["Ten"].ToString(), dtbChucNang);
                    }
                }
                //trvDanhSachChucNang.Override.ActiveNodeAppearance.FontData.Bold = DefaultableBoolean.True;
                trvDanhSachChucNang.ExpandAll();
                //node trợ giúp khi form load không có dấu +
                trvDanhSachChucNang.ActiveNode.Expanded = true;
            }
            catch (Exception ex) { Logger.LocalLogger.Instance().WriteMessage(ex); }
        }

        private void loadTreeRecursive(UltraTreeNode NodeChild, string ID_Goc, DataTable dt)
        {
            try
            {
                UltraTreeNode NewNode;
                DataRow[] drChucNang;
                drChucNang = dt.Select("[ID_Goc]='" + ID_Goc + "'");//Alway has value
                foreach (DataRow dr in drChucNang)
                {
                    DataRow[] drTemp = dt.Select("ID_Goc='" + dr["Ten"].ToString() + "'");

                    if (!NodeChild.Nodes.Exists(dr["Ten"].ToString()))
                    {
                        NewNode = NodeChild.Nodes.Add();
                        NewNode.Text = dr["Ten_HienThi"].ToString();
                        NewNode.Tag = dr["ID_DS_ChucNang"].ToString();
                        if (drTemp.Length > 0)
                        {
                            NewNode.Key = "ROOT~" + dr["Ten"].ToString();
                        }
                        else
                        {
                            NewNode.Key = dr["Ten"].ToString();
                        }
                        NewNode.LeftImages.Add(1);
                        NewNode.Override.ShowExpansionIndicator = ShowExpansionIndicator.Never;
                        NewNode.Override.NodeDoubleClickAction = NodeDoubleClickAction.ToggleExpansionWhenExpansionIndicatorVisible;
                        loadTreeRecursive(NewNode, dr["Ten"].ToString(), dt);
                    }
                }
            }
            catch (Exception ex) { Logger.LocalLogger.Instance().WriteMessage(ex); }
        }
        private void FrmPhanQuyenNhomNguoiDung_Load(object sender, System.EventArgs e)
        {
            //this.loadTreeDanhSachChucNang();
            Global.setDataToComboNhomNguoiDung(cboNhomNguoiDung);
            this.IsChange = false;
            this.caption = this.Text;
            scPhanQuyen.Enabled = false;
        }

        private void btnChon_Click(object sender, System.EventArgs e)
        {

        }
        private void UpdateTreeNodeStatus(Infragistics.Win.UltraWinTree.TreeNodesCollection node)
        {
            foreach (UltraTreeNode subNode in node)
            {
                DataRow[] drSub = dtPhanQuyen.Select("ID_DS_ChucNang = " + Convert.ToInt32(subNode.Tag) + " and ID_Nhom_NguoiDung =" + Convert.ToInt32(cboNhomNguoiDung.ActiveRow.Cells["ID_Nhom_NguoiDung"].Value));
                if (drSub.Length > 0)
                {
                    subNode.CheckedState = CheckState.Checked;
                }
                else
                {
                    subNode.CheckedState = CheckState.Unchecked;
                }
                if (subNode.Nodes.Count > 0)
                {
                    this.UpdateTreeNodeStatus(subNode.Nodes);
                }
            }
        }
        private void SetDataToTrvDanhSachChucNang()
        {
            trvDanhSachChucNang.Nodes.Clear();
            this.loadTreeDanhSachChucNang();
            this.UpdateTreeNodeStatus(trvDanhSachChucNang.Nodes);
        }

        private void trvDanhSachChucNang_Click(object sender, System.EventArgs e)
        {
            try
            {

                DataRow[] dr = dtPhanQuyen.Select("ID_DS_ChucNang = " + Convert.ToInt32(trvDanhSachChucNang.ActiveNode.Tag) + " and ID_Nhom_NguoiDung = " + Convert.ToInt32(cboNhomNguoiDung.ActiveRow.Cells["ID_Nhom_NguoiDung"].Value));
                if (dr.Length > 0)
                {
                    scPhanQuyen.Value = dr[0]["MaTruyCap"].ToString();
                    //trvDanhSachChucNang.ActiveNode = trvDanhSachChucNang.SelectedNodes[0];
                    //trvDanhSachChucNang.ActiveNode.Parent.CheckedState = CheckState.Checked;
                }
                else
                {
                    scPhanQuyen.Value = "00000";
                }
            }
            catch
            { }
        }
        private void UpdateTrvDanhSachChucNang(UltraTreeNode nodeActive)
        {
            DataRow[] dr = dtPhanQuyen.Select("ID_DS_ChucNang = " + Convert.ToInt32(nodeActive.Tag) + " and ID_Nhom_NguoiDung=" + Convert.ToInt32(cboNhomNguoiDung.ActiveRow.Cells["ID_Nhom_NguoiDung"].Value));
            if (scPhanQuyen.Value == "00000")
            {
                if (dr.Length > 0)
                {
                    switch (dr[0]["TrangThai"].ToString())
                    {
                        case "None":
                        case "Update":
                            dr[0]["TrangThai"] = "Delete";
                            dr[0]["MaTruyCap"] = "00000";
                            this.setChanged(true);
                            break;
                        case "New":
                            dr[0].Delete();
                            this.setChanged(true);
                            break;
                    }
                    nodeActive.CheckedState = CheckState.Unchecked;
                }

            }
            else
            {
                if (dr.Length > 0)
                {
                    dr[0]["MaTruyCap"] = scPhanQuyen.Value;
                    if (dr[0]["TrangThai"].ToString() != "New")
                    {
                        dr[0]["TrangThai"] = "Update";
                        this.setChanged(true);
                    }
                }
                else
                {
                    DataRow drw = dtPhanQuyen.NewRow();
                    drw["ID_DS_ChucNang"] = Convert.ToInt32(nodeActive.Tag);
                    drw["ID_Nhom_NguoiDung"] = Convert.ToInt32(cboNhomNguoiDung.ActiveRow.Cells["ID_Nhom_NguoiDung"].Value);
                    drw["MaTruyCap"] = scPhanQuyen.Value;
                    drw["TrangThai"] = "New";
                    dtPhanQuyen.Rows.Add(drw);
                    this.setChanged(true);
                }
                nodeActive.CheckedState = CheckState.Checked;
            }
        }

        private void scPhanQuyen_CheckBoxClicked()
        {
            this.trvDanhSachChucNang.AfterCheck -= new Infragistics.Win.UltraWinTree.AfterNodeChangedEventHandler(this.trvDanhSachChucNang_AfterCheck);
            if (trvDanhSachChucNang.ActiveNode != null)
            {
                this.UpdateTrvDanhSachChucNang(trvDanhSachChucNang.ActiveNode);
                this.setChanged(true);
                if (trvDanhSachChucNang.ActiveNode.Nodes.Count <= 0)
                {
                    string[] rootNode = trvDanhSachChucNang.ActiveNode.Key.Split('~');
                    switch (trvDanhSachChucNang.ActiveNode.CheckedState)
                    {
                        case CheckState.Checked:
                            if (rootNode[0] != "ROOT")
                            {
                                DataRow[] dr = dtPhanQuyen.Select("ID_DS_ChucNang = " + Convert.ToInt32(trvDanhSachChucNang.ActiveNode.Parent.Tag).ToString() + " and ID_Nhom_NguoiDung=" + Convert.ToInt32(cboNhomNguoiDung.ActiveRow.Cells["ID_Nhom_NguoiDung"].Value).ToString());
                                if (dr.Length == 0)
                                {
                                    DataRow drw = dtPhanQuyen.NewRow();
                                    drw["ID_DS_ChucNang"] = Convert.ToInt32(trvDanhSachChucNang.ActiveNode.Parent.Tag);
                                    drw["ID_Nhom_NguoiDung"] = Convert.ToInt32(cboNhomNguoiDung.ActiveRow.Cells["ID_Nhom_NguoiDung"].Value);
                                    drw["MaTruyCap"] = "11111";
                                    drw["TrangThai"] = "New";
                                    dtPhanQuyen.Rows.Add(drw);
                                    this.UpdateTrvDanhSachChucNang(trvDanhSachChucNang.ActiveNode.Parent);
                                }
                                trvDanhSachChucNang.ActiveNode.Parent.CheckedState = CheckState.Checked;
                                this.setChanged(true);
                            }
                            break;
                    }
                }
            }
            this.trvDanhSachChucNang.AfterCheck += new Infragistics.Win.UltraWinTree.AfterNodeChangedEventHandler(this.trvDanhSachChucNang_AfterCheck);
        }

        private void trvDanhSachChucNang_BeforeCheck(object sender, Infragistics.Win.UltraWinTree.BeforeCheckEventArgs e)
        {
            string[] keyRoot = e.TreeNode.Key.Split('~');
            if (keyRoot[0].Equals("ROOT"))
            {
                //e.TreeNode.Selected = true;	
                //trvDanhSachChucNang.ActiveNode = e.TreeNode;
            }
            else
            {
                //e.TreeNode.Selected = true;	
                //e.TreeNode.RootNode.Selected = false;
                //trvDanhSachChucNang.ActiveNode = e.TreeNode;
            }
        }

        private bool ValidChildCheck(UltraTreeNode parentNode)
        {
            foreach (UltraTreeNode node in parentNode.Nodes)
            {
                if (node.CheckedState == CheckState.Checked)
                {
                    return true;
                }
            }
            return false;
        }
        private void trvDanhSachChucNang_AfterCheck(object sender, Infragistics.Win.UltraWinTree.NodeEventArgs e)
        {
            //trvDanhSachChucNang.ActiveNode = e.TreeNode;
            //trvDanhSachChucNang.ActiveNode.Selected = true;
            string[] keyRoot = e.TreeNode.Key.Split('~');
            if (keyRoot[0].Equals("ROOT"))
            {
                foreach (UltraTreeNode node in e.TreeNode.Nodes)
                {
                    node.CheckedState = e.TreeNode.CheckedState;
                }
            }
            else
            {

            }
            if (e.TreeNode.CheckedState == CheckState.Checked)
            {
                //this.scPhanQuyen.CheckBoxClicked -= new SecurityControl.SecurityControl.CheckBoxClickedHandler(this.scPhanQuyen_CheckBoxClicked);
                scPhanQuyen.Value = "11111";
                this.UpdateTrvDanhSachChucNang(e.TreeNode);
                //this.scPhanQuyen.CheckBoxClicked += new SecurityControl.SecurityControl.CheckBoxClickedHandler(this.scPhanQuyen_CheckBoxClicked);
            }
            else
            {
                //this.scPhanQuyen.CheckBoxClicked -= new SecurityControl.SecurityControl.CheckBoxClickedHandler(this.scPhanQuyen_CheckBoxClicked);
                scPhanQuyen.Value = "00000";
                this.UpdateTrvDanhSachChucNang(e.TreeNode);
                //this.scPhanQuyen.CheckBoxClicked += new SecurityControl.SecurityControl.CheckBoxClickedHandler(this.scPhanQuyen_CheckBoxClicked);
            }
            this.scPhanQuyen.CheckBoxClicked += new SecurityControl.SecurityControl.CheckBoxClickedHandler(this.scPhanQuyen_CheckBoxClicked);
        }

        /// <summary>
        /// Lưu thông tin phân quyền vào cơ sở dữ liệu
        /// </summary>
        /// <param name="dt">DataTable chứa thông tin phân quyền</param>
        private void Save(DataTable dt)
        {
            try
            {
                //Duyệt các thông tin phân quyền để xác định trạng thái.
                foreach (DataRow dr in dt.Rows)
                {
                    switch (dr["TrangThai"].ToString())
                    {
                        //Nếu trạng thái là Cập nhật
                        case "Update":
                            ObjPhanQuyen.Update(Convert.ToInt32(dr["ID_PhanQuyen_Nhom"]), Convert.ToInt32(dr["ID_DS_ChucNang"]), dr["MaTruyCap"].ToString());
                            dr["TrangThai"] = "None";
                            break;
                        //Nếu trạng thái là thêm mới
                        case "New":
                            dr["ID_PhanQuyen_Nhom"] = ObjPhanQuyen.Insert(Convert.ToInt32(dr["ID_Nhom_NguoiDung"]), Convert.ToInt32(dr["ID_DS_ChucNang"]), dr["MaTruyCap"].ToString());
                            dr["TrangThai"] = "None";
                            break;
                        //Nếu trạng thái là xóa.
                        case "Delete":
                            ObjPhanQuyen.Delete(Convert.ToInt32(dr["ID_PhanQuyen_Nhom"]));
                            break;
                    }
                }
                dtPhanQuyen.Clear();
                ds = ObjPhanQuyen.ListByIDNhom(Convert.ToInt32(cboNhomNguoiDung.ActiveRow.Cells["ID_Nhom_NguoiDung"].Value));
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    DataRow drw = dtPhanQuyen.NewRow();
                    drw["ID_PhanQuyen_Nhom"] = Convert.ToInt32(dr["ID_PhanQuyen_Nhom"]);
                    drw["ID_DS_ChucNang"] = Convert.ToInt32(dr["ID_DS_ChucNang"]);
                    drw["ID_Nhom_NguoiDung"] = Convert.ToInt32(dr["ID_Nhom_NguoiDung"]);
                    drw["MaTruyCap"] = dr["MaTruyCap"].ToString();
                    drw["TrangThai"] = "None";
                    dtPhanQuyen.Rows.Add(drw);
                }
                MessageBox.Show("Lưu dữ liệu thành công.", QLNHK.BLL.ThongBao.MSG_Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Logger.LocalLogger.Instance().WriteMessage(ex);
            }
        }
        private void btnLuu_Click(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            this.Save(dtPhanQuyen);
            this.setChanged(false);
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void cboNhomNguoiDung_ValueChanged(object sender, System.EventArgs e)
        {
            try
            {
                if (cboNhomNguoiDung.ActiveRow.IsActiveRow)
                {
                    scPhanQuyen.Enabled = true;
                    this.trvDanhSachChucNang.AfterCheck -= new Infragistics.Win.UltraWinTree.AfterNodeChangedEventHandler(this.trvDanhSachChucNang_AfterCheck);
                    ds = ObjPhanQuyen.ListByIDNhom(Convert.ToInt32(cboNhomNguoiDung.ActiveRow.Cells["ID_Nhom_NguoiDung"].Value));
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        DataRow drw = dtPhanQuyen.NewRow();
                        drw["ID_PhanQuyen_Nhom"] = Convert.ToInt32(dr["ID_PhanQuyen_Nhom"]);
                        drw["ID_DS_ChucNang"] = Convert.ToInt32(dr["ID_DS_ChucNang"]);
                        drw["ID_Nhom_NguoiDung"] = Convert.ToInt32(dr["ID_Nhom_NguoiDung"]);
                        drw["MaTruyCap"] = dr["MaTruyCap"].ToString();
                        drw["TrangThai"] = "None";
                        dtPhanQuyen.Rows.Add(drw);
                    }
                    this.SetDataToTrvDanhSachChucNang();
                    this.trvDanhSachChucNang.AfterCheck += new Infragistics.Win.UltraWinTree.AfterNodeChangedEventHandler(this.trvDanhSachChucNang_AfterCheck);
                }
            }
            catch (Exception ex) { Logger.LocalLogger.Instance().WriteMessage(ex); }
        }

        private void btnMoRong_Click(object sender, System.EventArgs e)
        {
            if (btnMoRong.Tag.ToString().Equals("MORONG"))
            {
                btnMoRong.Text = "Thu hẹp cây chức năng";
                btnMoRong.Appearance.Image = imgTree.Images[3];
                trvDanhSachChucNang.ExpandAll();
                btnMoRong.Tag = "THUHEP";
            }
            else
            {
                btnMoRong.Text = "Mở rộng cây chức năng";
                btnMoRong.Appearance.Image = imgTree.Images[2];
                trvDanhSachChucNang.CollapseAll();
                btnMoRong.Tag = "MORONG";
            }
        }

        private void FrmPhanQuyenNhomNguoiDung_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (this.IsChange)
            {
                //Hiện hộp thoại hỏi người dùng có muốn lưu dữ liệu trước khi thoát không
                DialogResult result = MessageBox.Show(QLNHK.BLL.ThongBao.MSG_Warring_SaveData, QLNHK.BLL.ThongBao.MSG_Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    this.Save(dtPhanQuyen);
                    this.setChanged(false);
                }

            }
        }

        private void btnDong_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void trvDanhSachChucNang_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            try
            {
                //Khai báo một điểm
                Point pointInTree;
                UltraTreeNode nodeTree;
                //Nếu phím phải chuột
                if (e.Button == MouseButtons.Left)
                {
                    //Gắn tạo độ cho điểm tại vị trí chuột phải
                    pointInTree = new Point(e.X, e.Y);
                    //Lấy node thông qua tọa độ
                    nodeTree = trvDanhSachChucNang.GetNodeFromPoint(pointInTree);
                    //Node vừa lấy được set thuộc tính select - true
                    nodeTree.Selected = true;
                    //Active node vừa get được
                    trvDanhSachChucNang.ActiveNode = nodeTree;
                }
            }
            catch
            {
            }
        }

        private void cboNhomNguoiDung_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            e.Layout.Bands[0].Columns["Ten"].CellAppearance.Image = imgTree.Images[4];
            e.Layout.Bands[0].Columns["IsAdminGroup"].Hidden = true;
        }

        private void ultraGroupBox2_Click(object sender, EventArgs e)
        {

        }

    }
}
